import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        auth: {
            isAuthenticated: false,
            user: null
        }
    },
    mutations: {
        login(state, user) {
            state.auth.isAuthenticated = true
            state.auth.user = user
            // 可以在这里添加localStorage持久化
            localStorage.setItem('auth', JSON.stringify(state.auth))
        },
        logout(state) {
            state.auth.isAuthenticated = false
            state.auth.user = null
            localStorage.removeItem('auth')
        }
    },
    actions: {
        login({ commit }, credentials) {
            // 这里应该是您的登录逻辑，简单示例：
            if (credentials.username === 'admin' && credentials.password === '123456') {
                commit('login', { username: credentials.username })
                return true
            }
            return false
        }
    }
})